<?php

namespace app\common\model\transit;

use app\common\model\transit\Transitcompany;
use app\common\model\user\User as UserModel;
use think\Model;

class TransitUser extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'transituser';
    protected $pk    = 'TransitUserId';

    /**
     * 关联直播信息表
     */
    public function userinfo()
    {
        return $this->hasOne('app\common\model\user\User', 'UserId', 'UserId');
    }

    /**
     * 获取用户列表
     * @param  string $type [description]
     * @param  string $id   [description]
     * @return [type]       [description]
     */
    public static function getlist($type = 'tran', $id = '')
    {
        if ($type == 'tran') {
            //有企业id直接设置企业id为条件 没有则判断是否为管理者
            if(empty($data['tid'])){
                $company = Transitcompany::user_getinfo();
                $data    = TransitUser::where('TransitCompanyId', $company['TransitCompanyId']);
            }else{
                $data = TransitDriver::where('TransitCompanyId',$data['tid']);
            }
        } else if ($type == 'mana') {
            $data = TransitUser::where('TransitCompanyId', $id);
        } else if ($type == 'buss') {
            $data = TransitUser::where('TransitCompanyId', $id);
        }
        $visible = ['TransitUserId','UserId', 'userinfo.Name', 'userinfo.Iphone', 'userinfo.State'];
        $data    = $data->with('userinfo')->select();
        if (!empty($visible)) {
            $data = $data->visible($visible);
        }
        $rdata['userstate'] = UserModel::getStatusText();
        $rdata['list']      = $data;
        return $rdata;
    }

}
